package com.xzbd.springbootmybatiesdm.utils;

import java.util.Map;

public class PageQueryUtils{
    
    public static void parsePageParams(Map<String,Object> params) throws Exception {
        Object pageObj = params.get("page");
        
        if(pageObj ==null){
            throw new Exception("parameter page is null ");
        }

        Object limitObj  =  params.get("limit");
        if(limitObj == null){
            throw new Exception("parameter limit is null ");
        }
        
        Integer page = Integer.parseInt(pageObj.toString());
        Integer limit = Integer.parseInt(limitObj.toString());

        Integer offset = (page-1) * limit;
        if(offset < 0){
            throw new Exception("offset must grantter than 0 , input page is :" 
            + page + " ,limit is : " + limit);
        }
        params.put("offset", offset);
    }
}